package com.csproj.system.resource;

import com.codahale.metrics.annotation.Timed;
import com.csproj.siiat.base.common.dto.BaseDTO;
import com.csproj.siiat.base.common.repository.PageableTools;
import com.csproj.siiat.web.rest.errors.BadRequestAlertException;
import com.csproj.siiat.web.rest.util.HeaderUtil;
import com.csproj.system.service.SysLogsService;
import com.csproj.system.service.dto.SysLogsDTO;
import io.github.jhipster.web.util.ResponseUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.net.URISyntaxException;

import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * REST controller for managing SysLogs.
 */
@RestController
@RequestMapping("/api/siiat/v1")
public class SysLogsResource {

    private final Logger log = LoggerFactory.getLogger(SysLogsResource.class);

    private static final String ENTITY_NAME = "sysLogs";

    private final SysLogsService sysLogsService;

    public SysLogsResource(SysLogsService sysLogsService) {
        this.sysLogsService = sysLogsService;
    }


    /**
     * GET  /sys-logs : get all the sysLogs with pages.
     *
     * @return the ResponseEntity with status 200 (OK) and the list of sysLogs in body
     */
    @GetMapping("/syslogs")
    @Timed
    public BaseDTO getLogsBypage(@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
                                 @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                 @RequestParam(value = "name", required = false) String name,
                                 @RequestParam(value = "roleId",required = false) String roleId,
                                 @RequestParam(value = "keyWord", required = false) String keyWord,
                                 @RequestParam(value = "startTime", required = false) ZonedDateTime startTime,
                                 @RequestParam(value = "endTime", required = false) ZonedDateTime endTime
    ) {
        log.debug("REST request to get all UserInfos");
        Pageable pageable = PageableTools.basicPage(pageNumber, pageSize);

        Map<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put("keyWord", keyWord);
        queryParams.put("name",name);
        queryParams.put("startTime",startTime);
        queryParams.put("endTime",endTime);
        queryParams.put("roleId",roleId);

        return sysLogsService.findPageList(queryParams, pageable);
    }


}
